﻿using UnityEngine;
using System.Collections;

///Developed By Indie Studio
///https://assetstore.unity.com/publishers/9268
///www.indiestd.com
///info@indiestd.com

namespace IndieStudio.BugsBang.Utility
{
	[DisallowMultipleComponent]
	public class SingletonManager : MonoBehaviour
	{
		/// <summary>
		/// The list of singeltons.
		/// </summary>
		public GameObject[] values;

		// Use this for initialization
		void Awake ()
		{
			InstantiateValues ();
		}

		/// <summary>
		/// Instantiates the values.
		/// </summary>
		private void InstantiateValues ()
		{
			if (values == null) {
				return;
			}

			foreach (GameObject value in values) {
				if (value == null) {
					Debug.LogWarning ("Undefined value is found in SingletonManager component");
					continue;
				}
				if (GameObject.Find (value.name) == null) {
					GameObject temp = Instantiate (value, Vector3.zero, Quaternion.identity) as GameObject;
					temp.transform.eulerAngles = value.transform.eulerAngles;
					temp.name = value.name;
				}
			}
		}
	}
}